//
//  API.m
//  KiklinkApp
//
//  Created by LF on 14-9-28.
//  Copyright (c) 2014年 Kiklink. All rights reserved.
//

#import "API.h"
#import "APIManager.h"
#import "OrderDetailRequestAssist.h"

NSString* const URL_LOGIN_KIKLINK = @"kailian/CmsUserInfo/login.do?ajax=ajax";
NSString* const URL_LOGOUT_KIKLINK = @"kailian/CmsUserInfo/logout.do?ajax=ajax";
NSString* const URL_REGIST_KIKLINK = @"kailian/CmsUserInfo/regist.do?ajax=ajax";
NSString* const URL_RESET_PASSWORD = @"kailian/CmsUserInfo/mobpasswd.do?ajax=ajax";
NSString* const URL_GET_VERIFICATION_CODE = @"kailian/CmsUserInfo/mobileValidnum.do";
NSString* const URL_THIRDPARTY_LOGIN_KIKLINK = @"kailian/CmsUserInfo/third.do?ajax=ajax";


NSString* const URL_HOME_ACTIVITY_IMAGE = @"kailian/CmsBiaodanDetail/listAjax.do?inputListId=20&ajax=ajax";
NSString* const URL_HOME_RECOMMEND = @"kailian/KlSellerProduct/search.do?status=1&ajax=ajax";
NSString* const URL_PRODUCT_DETAIL = @"kailian/KlSellerProduct/show.do?ajax=ajax";
NSString* const URL_COURSE_SEARCH = @"kailian/KlSellerProduct/search.do?status=1&ajax=ajax";
NSString* const URL_COACHES = @"kailian/KlSellerProduct/coaches.do?ajax=ajax";
NSString* const URL_COMMENT_OF_PRODUCT = @"kailian/KlSellerProduct/productcomment.do?ajax=ajax";
NSString* const URL_COMMENT_ADD = @"kailian/CmsCommonComment/savecomment.do?ajax=ajax&targettype=20";
NSString* const URL_COMMENT_UNCOMMENTED = @"kailian/KlShoppingShoppingcartproduct/myclass.do?ajax=ajax&payed=1&nocommened=1";
NSString* const URL_SELL_RECORD = @"kailian/KlShoppingShoppingcartproduct/listAjax.do?sort=id%20desc";



NSString* const URL_FAVOURITE_ITEM = @"kailian/CmsCommonSaved/mysavetype.do?ajax=ajax";
NSString* const URL_FAVOURITE_ITEM_ADD = @"kailian/CmsCommonSaved/addSave.do?ajax=ajax";
NSString* const URL_FAVOURITE_ITEM_REMOVE = @"kailian/CmsCommonSaved/deleteSave.do?ajax=ajax";

NSString* const URL_SHOP_DETAIL = @"kailian/KlSellerShop/show.do?ajax=ajax";
NSString* const URL_ORDER_ALL = @"kailian/KlShoppingOrder/userorders.do?ajax=ajax";
NSString* const URL_ORDER_PAYED = @"kailian/KlShoppingOrder/userorders.do?ajax=ajax&payed=1";
NSString* const URL_ORDER_UNPAYED = @"kailian/KlShoppingOrder/userorders.do?ajax=ajax&waitpay=1";
NSString* const URL_ORDER_DETAIL = @"kailian/KlShoppingShoppingcartproduct/userorderdetail.do?ajax=ajax";
NSString* const URL_ORDER_DO_ADD = @"kailian/KlShoppingShoppingcartproduct/waitpay.do?ajax=ajax";
NSString* const URL_ORDER_SHOP_CHART = @"kailian/KlShoppingShoppingcartproduct/shopCar.do?ajax=ajax";




NSString* const URL_BIND_PHONE_NUMBER = @"kailian/CmsUserInfo/bindmobile.do?ajax=ajax";

NSString* const URL_MESSAGE_USER = @"kailian/CmsCommonMessage/messages.do?ajax=ajax";
NSString* const URL_MESSAGE_SYSTEM = @"kailian/CmsCommonMessage/messages.do?ajax=ajax&mtype=1";
NSString* const URL_MESSAGE_DELETED = @"kailian/CmsCommonMessage/messages.do?ajax=ajax&mtype=2";
NSString* const URL_MESSAGE_DO_DELETE = @"kailian/CmsCommonMessage/status.do?ajax=ajax&status=-1";
NSString* const URL_MESSAGE_DO_RESTORE = @"kailian/CmsCommonMessage/status.do?ajax=ajax&status=1";
NSString* const URL_MESSAGE_DO_REPLY = @"kailian/CmsCommonMessage/postmessage.do?ajax=ajax";




@implementation API

//Account ----------------------------------------------------------------

+ (void)loginKiklinkWithUsername:(NSString*)username Password:(NSString*)password Callback:(Callback) callback
{
    KLLogStatic(self, @"loginKiklink");
    
    NSDictionary *parameters = @{@"moboremail": username, @"passwd": password};
    [APIManager request:URL_LOGIN_KIKLINK
             parameters:parameters
               callback:^(int stateCode, NSString* word, id content)
     {
         callback(stateCode, word, content);
     }
     ];
}

+ (void)logoutKiklinkWithCallback:(Callback) callback
{
    KLLogStatic(self, @"logoutKiklink");
    
    NSDictionary *parameters = @{};
    [APIManager request:URL_LOGOUT_KIKLINK
             parameters:parameters
               callback:^(int stateCode, NSString* word, id content)
     {
         callback(stateCode, word, content);
     }
     ];
}

//发送验证码
+ (void)sendVerificationCodeToPhoneNumber:(NSString *)phoneNumber callback:(Callback)callback
{
    KLLogStatic(self, @"sendVerificationCode");
    
    NSDictionary *parameters = @{@"mobile": phoneNumber};
    [APIManager request:URL_GET_VERIFICATION_CODE
             parameters:parameters
               callback:^(int stateCode, NSString* word, id content)
     {
         if(stateCode > 0)
         {
             callback(stateCode, word, content);
         }
         else
         {
             //			 NSString *err_mobile = [content objectForKey:@"err_mobile"];
             //			 if(stateCode == FAILURE_RETURN_ERRER_CODE)
             //			 {
             //				 word = [NSString stringWithFormat:@"%@, %@", word, err_mobile];
             //			 }
             callback(stateCode, word, content);
         }
     }
     ];
}

+ (void)registKiklinkWithPhoneNumber:(NSString*)phoneNumber verificationCode:(NSString*)verificationCode displayName:(NSString*)displayName password:(NSString*)password Callback:(Callback) callback
{
    KLLogStatic(self, @"registKiklink");
    
    NSDictionary *parameters = @{@"mobile":phoneNumber, @"mobilevalidnum":verificationCode, @"thirdType":@"mobile", @"username": displayName, @"passwd": password, @"repasswd": password};
    [APIManager request:URL_REGIST_KIKLINK
             parameters:parameters
               callback:^(int stateCode, NSString* word, id content)
     {
         callback(stateCode, word, content);
     }
     ];
}

+ (void)resetPasswordWithPhoneNumber:(NSString*)phoneNumber verificationCode:(NSString*)verificationCode password:(NSString*)password Callback:(Callback) callback
{
    KLLogStatic(self, @"resetPassword");
    
    NSDictionary *parameters = @{@"mobile":phoneNumber, @"mobilevalidnum":verificationCode, @"passwd": password};
    [APIManager request:URL_RESET_PASSWORD
             parameters:parameters
               callback:^(int stateCode, NSString* word, id content)
     {
         callback(stateCode, word, content);
     }
     ];
}

//thirdType:qq或weibo
+ (void)thirdPartyLoginKiklinkWithType:(NSString*)thirdType id:(NSString*)userId token:(NSString*)token displayName:(NSString*)displayName sex:(NSNumber*)sex Callback:(Callback) callback
{
    KLLogStatic(self, @"thirdPartyLogin");
    
    NSDictionary *parameters = @{@"thirdType":thirdType, @"openid":userId, @"token":token, @"username": displayName};
    [APIManager request:URL_THIRDPARTY_LOGIN_KIKLINK
             parameters:parameters
               callback:^(int stateCode, NSString* word, id content)
     {
         callback(stateCode, word, content);
     }
     ];
}

+ (void)bindPhoneNumber:(NSString *)phoneNumber callback:(Callback)callback
{
    KLLogStatic(self, @"bindPhoneNumber");
    
    NSDictionary *parameters = @{@"mobile": phoneNumber};
    [APIManager request:URL_BIND_PHONE_NUMBER
             parameters:parameters
               callback:^(int stateCode, NSString* word, id content)
     {
         if(stateCode > 0)
         {
             callback(stateCode, word, content);
         }
         else
         {
             NSString *err_mobile = [content objectForKey:@"err_mobile"];
             if(stateCode == FAILURE_RETURN_ERRER_CODE)
             {
                 word = [NSString stringWithFormat:@"%@, %@", word, err_mobile];
             }
             callback(stateCode, word, content);
         }
     }
     ];
}

+ (void)homeActivityImageWithCallback: (Callback)callback
{
    KLLogStatic(self, @"homeActivityImage");
    [APIManager request:URL_HOME_ACTIVITY_IMAGE parameters:nil callback:^(int stateCode, NSString *word, id content) {
        
        if(stateCode > 0)
        {
            NSArray *rows = [content objectForKey:@"rows"];
            
            NSMutableArray *returnArray = [NSMutableArray array];
            
            for (NSDictionary *homeItemDic in rows)
            {
                HomeImage *homeItem = [[HomeImage alloc] initWithDictionary:homeItemDic];
                NSString *contentString = [NSString stringWithFormat:@"%@", homeItem.content];
                
                NSError *praseError = nil;
                NSDictionary* contentObj = [NSJSONSerialization JSONObjectWithData:[contentString dataUsingEncoding:NSUTF8StringEncoding] options:0 error:&praseError];
                if(praseError != nil)
                {
                    callback(FAILURE_PARSE_ERROR, [StatusCode getWordByCode:FAILURE_PARSE_ERROR], content);
                }
                
                Content *content = [[Content alloc] initWithDictionary:contentObj];
                homeItem.content = content;
                [returnArray addObject:homeItem];
            }
            callback(stateCode, word, returnArray);
        }
        else
        {
            callback(stateCode, word, content);
        }
        
    }];
}

+ (void)homeRecommendPageWithPageNumber:(NSNumber *)pageNumber Callback:(Callback)callback
{
    KLLogStatic(self, @"homeRecommend");
    
    NSDictionary *parameters = @{@"pageno": pageNumber};
    [APIManager request: URL_HOME_RECOMMEND parameters: parameters callback:^(int stateCode, NSString *word, id content) {
        if(stateCode > 0)
        {
            NSDictionary *pageObj = [content objectForKey:@"page"];
            
            ProductPage *page = [[ProductPage alloc] initWithDictionary:pageObj];
            callback(stateCode, word, page);
        }
        else{
            callback(stateCode, word, content);
        }
    }];
}

+(void)shopDetailWithShopId:(NSNumber*)shopId Callback:(Callback)callback
{
    KLLogStatic(self, @"shopDetail");
    
    NSDictionary *parameters = @{@"id": shopId};
    
    [APIManager request:URL_SHOP_DETAIL parameters:parameters callback:^(int stateCode, NSString *word, id content) {
        
        if(stateCode > 0)
        {
            NSDictionary *shopObj = [content objectForKey:@"shop"];
            Shop* shop = [[Shop alloc] initWithDictionary:shopObj];
            
            callback(stateCode, word, shop);
        }
        else
        {
            callback(stateCode, word, content);
        }
    }];
}


//Product -------------------------------------------------------------------

+ (void)productDetailWithId:(NSNumber *)Id Callback:(Callback)callback
{
    KLLogStatic(self, @"productDetail");
    
    NSDictionary *parameters = @{@"id": Id};
    [APIManager request:URL_PRODUCT_DETAIL parameters:parameters callback:^(int stateCode, NSString *word, id content) {
        
        if(stateCode > 0)
        {
            NSDictionary *productDic = [content objectForKey:@"product"];
            Product *product = [[Product alloc] initWithDictionary:productDic];
            callback(stateCode, word, product);
        }
        else{
            callback(stateCode, word, content);
        }
    }];
}

+ (void)courseSearchWithKeyword:(NSString *)keyword distance:(NSNumber *)distance tags:(NSString *)tags category:(NSNumber*)category sortStyle:(NSString *)sortStyle pageNumber:(NSNumber *)pageNumber Callback:(Callback)callback
{
    KLLogStatic(self, @"courseSearch");
    
    NSDictionary *parameters = @{@"pageno": pageNumber, @"name": keyword, @"sort": sortStyle, @"distance": distance, @"tags": tags, @"cat":category};
    
    [APIManager request:URL_COURSE_SEARCH parameters:parameters callback:^(int stateCode, NSString *word, id content) {
        
        if(stateCode > 0)
        {
            NSDictionary *pageObj = [content objectForKey:@"page"];
            
            ProductPage *page = [[ProductPage alloc] initWithDictionary:pageObj];
            callback(stateCode, word, page);
        }
        else{
            callback(stateCode, word, content);
        }
    }];
}

+(void)coachWithProductId:(NSNumber*)productId Callback:(Callback)callback
{
    KLLogStatic(self, @"coaches");
    
    NSDictionary *parameters = @{@"id": productId};
    
    [APIManager request:URL_COACHES parameters:parameters callback:^(int stateCode, NSString *word, id content) {
        
        if(stateCode > 0)
        {
            
            NSArray *coachesObj = [content objectForKey:@"coaches"];
            NSMutableArray *coaches= [NSMutableArray array];
            for (NSDictionary *coachObj in coachesObj)
            {
                Coach *coach = [[Coach alloc] initWithDictionary:coachObj];
                [coaches addObject:coach];
            }
            
            callback(stateCode, word, coaches);
            
        }
        else
        {
            callback(stateCode, word, content);
        }
    }];
}

+(void)commentPageWithProductId:(NSNumber*)productId PageNumber:(NSNumber*)pageNumber Callback:(Callback)callback
{
    KLLogStatic(self, @"comment");
    
    NSDictionary *parameters = @{@"id": productId, @"pageno": pageNumber};
    
    [APIManager request:URL_COMMENT_OF_PRODUCT parameters:parameters callback:^(int stateCode, NSString *word, id content) {
        
        if(stateCode > 0)
        {
            NSDictionary *commentPageObj = [content objectForKey:@"comments"];
            CommentPage* commentPage = [[CommentPage alloc] initWithDictionary:commentPageObj];
            
            callback(stateCode, word, commentPage);
        }
        else
        {
            callback(stateCode, word, content);
        }
    }];
}

+(void)uncommentedOrderItemPageWithPageNumber:(NSNumber*)pageNumber Callback:(Callback)callback
{
    KLLogStatic(self, @"uncommentedOrderItem");
    
    NSDictionary *parameters = @{@"pageno": pageNumber};
    
    [APIManager request:URL_COMMENT_UNCOMMENTED parameters:parameters callback:^(int stateCode, NSString *word, id content) {
        
        if(stateCode > 0)
        {
            NSDictionary *orderItemPageObj = [content objectForKey:@"page2"];
            OrderItemPage* orderItemPage = [[OrderItemPage alloc] initWithDictionary:orderItemPageObj];
            
            callback(stateCode, word, orderItemPage);
        }
        else
        {
            callback(stateCode, word, content);
        }
    }];
}

+(void)addCommentWithProductId:(NSNumber*)productId comment:(NSString*)comment pointDescriptionMath:(NSNumber*)pointDescriptionMath pointProfessional:(NSNumber*) pointProfessional pointServiceAttitude:(NSNumber*)pointServiceAttitude pointAppointmentSuccessful:(NSNumber*)pointAppointmentSuccessful callback:(Callback)callback
{
    KLLogStatic(self, @"addComment");
    
    NSDictionary *parameters = @{@"targetid": productId, @"cont": comment, @"pointDescriptionMath": pointDescriptionMath, @"pointPerfational": pointProfessional, @"pointServiceAttitude": pointServiceAttitude, @"pointAppointmentSuccessful": pointAppointmentSuccessful};
    
    [APIManager request:URL_COMMENT_ADD parameters:parameters callback:^(int stateCode, NSString *word, id content) {
        
        callback(stateCode, word, content);
    }];
}

//! API有错误，缺少re
+(void)sellRecordPageWithProductId:(NSNumber*)productId PageNumber:(NSNumber*)pageNumber Callback:(Callback)callback
{
    KLLogStatic(self, @"sellRecord");
    
    NSDictionary *parameters = @{@"productid": productId, @"pageno": pageNumber};
    
    [APIManager request:URL_SELL_RECORD parameters:parameters callback:^(int stateCode, NSString *word, id content) {
        
        if(stateCode > 0 || stateCode == FAILURE_PARSE_ERROR)
        {
            NSArray *recordArrayObj = [content objectForKey:@"rows"];
            NSMutableDictionary *pageObj = [[content objectForKey:@"page"] mutableCopy];
            [pageObj setValue:recordArrayObj forKey:@"result"];
            
            SellRecordPage* page = [[SellRecordPage alloc] initWithDictionary:pageObj];
            
            callback(SUCCESS, word, page);
        }
        else
        {
            callback(stateCode, word, content);
        }
        
    }];
}

//Favourite ---------------------------------------------------------------

+(void)favouriteItemPageWithItemType:(NSNumber*)itemType itemId:(NSNumber*)itemId pageNumber:(NSNumber*)pageNumber Callback:(Callback)callback
{
    KLLogStatic(self, @"favouriteItem");
    
    NSDictionary *parameters = @{@"type": itemType, @"targetId":itemId, @"pageno": pageNumber};
    
    [APIManager request:URL_FAVOURITE_ITEM parameters:parameters callback:^(int stateCode, NSString *word, id content) {
        
        if(stateCode > 0)
        {
            NSDictionary *favouriteItemPageObj = [content objectForKey:@"page"];
            FavouriteItemPage* favouriteItemPage = [[FavouriteItemPage alloc] initWithDictionary:favouriteItemPageObj];
            
            callback(stateCode, word, favouriteItemPage);
        }
        else
        {
            callback(stateCode, word, content);
        }
    }];
}

+(void)favouriteProductPageWithPageNumber:(NSNumber*)pageNumber Callback:(Callback)callback
{
    [API favouriteItemPageWithItemType:@20 itemId:@0 pageNumber:pageNumber Callback:^(int stateCode, NSString *word, id content) {
        callback(stateCode, word, content);
    }];
}

+(void)favouriteProductPageWithProductId:(NSNumber*)itemId Callback:(Callback)callback
{
    [API favouriteItemPageWithItemType:@20 itemId:itemId pageNumber:@0 Callback:^(int stateCode, NSString *word, id content) {
        callback(stateCode, word, content);
    }];
}

+(void)favouriteShopPageWithPageNumber:(NSNumber*)pageNumber Callback:(Callback)callback
{
    [API favouriteItemPageWithItemType:@10 itemId:@0 pageNumber:pageNumber Callback:^(int stateCode, NSString *word, id content) {
        callback(stateCode, word, content);
    }];
}

+(void)addFavouriteItemWithItemType:(NSNumber*) itemType ItemId:(NSNumber*)itemId Callback:(Callback)callback
{
    KLLogStatic(self, @"addFavouriteItem");
    
    NSDictionary *parameters = @{@"type": itemType, @"targetId": itemId};
    
    [APIManager request:URL_FAVOURITE_ITEM_ADD parameters:parameters callback:^(int stateCode, NSString *word, id content) {
        
        callback(stateCode, word, content);
    }];
}

+(void)addFavouriteProductWithProductId:(NSNumber*)itemId Callback:(Callback)callback
{
    [API addFavouriteItemWithItemType:@20 ItemId:itemId Callback:^(int stateCode, NSString *word, id content) {
        callback(stateCode, word, content);
    }];
}

+(void)addFavouriteShopWithShopId:(NSNumber*)itemId Callback:(Callback)callback
{
    [API addFavouriteItemWithItemType:@10 ItemId:itemId Callback:^(int stateCode, NSString *word, id content) {
        callback(stateCode, word, content);
    }];
}

+(void)removeFavouriteItemWithFavouriteId:(NSNumber*)itemId Callback:(Callback)callback
{
    KLLogStatic(self, @"removeFavouriteItem");
    
    NSDictionary *parameters = @{@"id": itemId};
    
    [APIManager request:URL_FAVOURITE_ITEM_REMOVE parameters:parameters callback:^(int stateCode, NSString *word, id content) {
        
        callback(stateCode, word, content);
    }];
}

//Order ------------------------------------------------------

+(void)generalOrderPageWithSubURL:(NSString*)subURL PageNumber:(NSNumber*)pageNumber Callback:(Callback)callback
{
    KLLogStatic(self, @"order");
    
    NSDictionary *parameters = @{@"pageno":pageNumber};
    
    [APIManager request:subURL parameters:parameters callback:^(int stateCode, NSString *word, id content) {
        
        if(stateCode > 0)
        {
            NSDictionary *orderPageObj = [content objectForKey:@"page"];
            OrderPage* orderPage = [[OrderPage alloc] initWithDictionary:orderPageObj];
            
            callback(stateCode, word, orderPage);
        }
        else
        {
            callback(stateCode, word, content);
        }
    }];
}

+(void)myOrderPageWithPageNumber:(NSNumber*)pageNumber Callback:(Callback)callback
{
    [API generalOrderPageWithSubURL:URL_ORDER_ALL PageNumber:pageNumber Callback:^(int stateCode, NSString *word, id content) {
        callback(stateCode, word, content);
    }];
}

+(void)payedOrderPageWithPageNumber:(NSNumber*)pageNumber Callback:(Callback)callback
{
    [API generalOrderPageWithSubURL:URL_ORDER_PAYED  PageNumber:pageNumber Callback:^(int stateCode, NSString *word, id content) {
        callback(stateCode, word, content);
    }];
}

+(void)unpayedOrderPageWithPageNumber:(NSNumber*)pageNumber Callback:(Callback)callback
{
    [API generalOrderPageWithSubURL:URL_ORDER_UNPAYED  PageNumber:pageNumber Callback:^(int stateCode, NSString *word, id content) {
        callback(stateCode, word, content);
    }];
}


//获取单页订单详情
+(void)orderDetailWithOrderId:(NSNumber*)orderId PageNumber:(NSNumber*)pageNumber Callback:(Callback)callback
{
    KLLogStatic(self, @"orderDetail");
    
    NSDictionary *parameters = @{@"orderid": orderId, @"pageno":pageNumber};
    
    [APIManager request:URL_ORDER_DETAIL parameters:parameters callback:^(int stateCode, NSString *word, id content) {
        
        if(stateCode > 0)
        {
            NSDictionary *orderObj = [content objectForKey:@"order"];
            OrderHeader* order = [[OrderHeader alloc] initWithDictionary:orderObj];
            
            NSDictionary *orderItemPageObj = [content objectForKey:@"page"];
            OrderItemPage* orderItemPage = [[OrderItemPage alloc] initWithDictionary:orderItemPageObj];
            
            NSDictionary *orderDetail = @{@"order":order, @"orderItemPage":orderItemPage};
            callback(stateCode, word, orderDetail);
        }
        else
        {
            callback(stateCode, word, content);
        }
    }];
}

+(void)orderDetailWithOrderId:(NSNumber*)orderId Callback:(Callback)callback
{
    [[[OrderDetailRequestAssist alloc]init]startWithOrderId:orderId callback:callback];
}

+(void)addOrderWithProductId:(NSNumber*)productId count:(NSNumber*)count callback:(Callback)callback
{
    KLLogStatic(self, @"addOrder");
    
    [APIManager request:URL_ORDER_SHOP_CHART parameters:nil callback:^(int stateCode, NSString *word, id content) {
        
        if(stateCode > 0)
        {
            NSDictionary *orderObj = [content objectForKey:@"order"];
            OrderHeader *orderHeader = [[OrderHeader alloc]initWithDictionary:orderObj];
            NSNumber *orderId = orderHeader.id;
            
            NSString *itemKey = [[NSString alloc]initWithFormat:@"%@%@", @"name", productId];
            NSDictionary *parameters = @{@"orderid": orderId, itemKey:count};
            
            [APIManager request:URL_ORDER_DO_ADD parameters:parameters callback:^(int stateCode, NSString *word, id content) {
                
                callback(stateCode, word, content);
            }];
        }
        else
        {
            callback(stateCode, word, content);
        }
    }];
}


//消息------------------------------------------------------------------

+(void)userMessageWithPageNumber:(NSNumber*)pageNumber callback:(Callback)callback
{
    KLLogStatic(self, @"getUserMessage");
    
    NSDictionary *parameters = @{@"pageno": pageNumber};
    
    [APIManager request:URL_MESSAGE_USER parameters:parameters callback:^(int stateCode, NSString *word, id content) {
        
        if(stateCode > 0)
        {
            NSDictionary *messagePageObj = [content objectForKey:@"p1"];
            MessagePage* messagePage = [[MessagePage alloc] initWithDictionary:messagePageObj];
            
            callback(stateCode, word, messagePage);
        }
        else
        {
            callback(stateCode, word, content);
        }
    }];
}

+(void)systemMessageWithPageNumber:(NSNumber*)pageNumber callback:(Callback)callback
{
    KLLogStatic(self, @"getSystemMessage");
    
    NSDictionary *parameters = @{@"pageno": pageNumber};
    
    [APIManager request:URL_MESSAGE_SYSTEM parameters:parameters callback:^(int stateCode, NSString *word, id content) {
        
        if(stateCode > 0)
        {
            NSDictionary *messagePageObj = [content objectForKey:@"p1"];
            MessagePage* messagePage = [[MessagePage alloc] initWithDictionary:messagePageObj];
            
            callback(stateCode, word, messagePage);
        }
        else
        {
            callback(stateCode, word, content);
        }
    }];
}

+(void)deletedMessageWithPageNumber:(NSNumber*)pageNumber callback:(Callback)callback
{
    KLLogStatic(self, @"getDeletedMessage");
    
    NSDictionary *parameters = @{@"pageno": pageNumber};
    
    [APIManager request:URL_MESSAGE_DELETED parameters:parameters callback:^(int stateCode, NSString *word, id content) {
        
        if(stateCode > 0)
        {
            NSDictionary *messagePageObj = [content objectForKey:@"p3"];
            MessagePage* messagePage = [[MessagePage alloc] initWithDictionary:messagePageObj];
            
            callback(stateCode, word, messagePage);
        }
        else
        {
            callback(stateCode, word, content);
        }
    }];
}

+(void)deleteMessageWithMessageId:(NSNumber*)messageId callback:(Callback)callback
{
    KLLogStatic(self, @"deleteMessage");
    
    NSDictionary *parameters = @{@"id": messageId};
    
    [APIManager request:URL_MESSAGE_DO_DELETE parameters:parameters callback:^(int stateCode, NSString *word, id content) {
        
        callback(stateCode, word, content);
    }];
}

+(void)restoreMessageWithMessageId:(NSNumber*)messageId callback:(Callback)callback
{
    KLLogStatic(self, @"restoreMessage");
    
    NSDictionary *parameters = @{@"id": messageId};
    
    [APIManager request:URL_MESSAGE_DO_RESTORE parameters:parameters callback:^(int stateCode, NSString *word, id content) {
        
        callback(stateCode, word, content);
    }];
}

+(void)replyMessageWithMessageId:(NSNumber*)messageId content:(NSString*)content callback:(Callback)callback
{
    KLLogStatic(self, @"replyMessage");
    
    NSDictionary *parameters = @{@"targetid": messageId, @"content":content};
    
    [APIManager request:URL_MESSAGE_DO_REPLY parameters:parameters callback:^(int stateCode, NSString *word, id content) {
        
        callback(stateCode, word, content);
    }];
}

@end
